import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-09-26
 * Time: 20:36
 */
public class CardDemo {
    private final String[] SUITS = {"♥", "♠", "♦", "♣"};

    /** 买一副牌
     * 一副牌有52张
     *      J   Q   K
     *      11  12  13
     */

    public List<Card>buyDeck() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(SUITS[i], j);
                cardList.add(card);
            }
        }
        return cardList;
    }

    //洗乱牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();

        for (int i = cardList.size() - 1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList, i, index);
        }
    }

    private void swap(List<Card> cardList , int a, int b) {
        Card tmp = cardList.get(a);
        cardList.set(a, cardList.get(b));
        cardList.set(b, tmp);
    }


    /**
     * 揭牌
     * 3个人，每个人轮流揭五张牌
     */
    public void getCard(List<Card> cardList) {
        List<List<Card>> hands = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        //三个人轮流抓5张牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println("第一个揭牌");
        System.out.println(hand1);
        System.out.println("第二个揭牌");
        System.out.println(hand2);
        System.out.println("第三个揭牌");
        System.out.println(hand3);
    }

}
